package com.example.world.servlet;

import com.example.world.dao.CountryDAO;
import com.example.world.domain.City;
import com.example.world.domain.Country;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.sql.SQLException;


@WebServlet("/CountryServlet")
public class CountryServlet  extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        String code = req.getParameter("code");

        CountryDAO dao = new CountryDAO();

        try {
            Country country =  dao.findByCode(code);
            if(country!=null)
            {
                resp.setHeader("Content-Type","text/html;charset=utf-8");
                resp.getWriter().print("查找成功，即将为您跳转主页......");
                req.setAttribute("country",country);
                req.getRequestDispatcher("country.jsp").forward(req, resp);

            }
            else
            {
                resp.getWriter().print("find fail");
            }
        } catch (SQLException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }




    }
    }

